package com.cyzy.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyzy.dao.ClassCourseDao;
import com.cyzy.dto.Result;
import com.cyzy.pojo.Class;
import com.cyzy.pojo.Course;
import com.cyzy.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/class")
public class ClassController {

    @Autowired
    private ClassService classService;

//    查询所有班级
    @GetMapping("/selectClass")
    public Result selectClass(ClassCourseDao classCourseDao){
        Page<ClassCourseDao> classList = classService.selectClass(classCourseDao);
        return Result.ok().data("classList",classList);
    }

//    根据课程名称查询班级
    @GetMapping("/selectClassBycourseName")
    public Result selectClassBycourseName(ClassCourseDao classCourseDao){
        List<ClassCourseDao> classList = classService.selectClassBycourseName(classCourseDao);
        return Result.ok().data("classList",classList);
    }

//    查询所有课程
    @GetMapping("/selectAllCourse")
    public Result selectAllCourse(Course course){
        List<Course> courseList = classService.selectAllCourse(course);
        return Result.ok().data("courseList",courseList);
    }

//    新增班级
    @PostMapping("/addClass")
    public Result addClass(@RequestBody Class classs){
        int i = classService.addClass(classs);
        return Result.ok();
    }

//    分班
//    查询所有学生   在studentController有
//

//    查询班级
    @GetMapping("/getClass")
    public Result getAllClass(Class classs){
        List<Class> classList = classService.getAllClass(classs);
        return Result.ok().data("classList",classList);
    }



    @GetMapping("/getClassStudent")
    public Result getClassStudent(int classId, int courseId){
        return classService.getClassStudent(classId, courseId);
    }


    @PostMapping("/classManagement")
    public Result classManagement(@RequestBody ClassCourseDao classCourseDao){
        return classService.classManagement(classCourseDao);
    }

    @PutMapping("/updateClass")
    public Result updateClass(@RequestBody Class classs){
        int i = classService.updateClass(classs);
        return Result.ok();
    }

//    修改回显
    @GetMapping("/showClass")
    public Result showClass(Class classs){
        Class showClass = classService.showClass(classs);
        return Result.ok().data("showClass",showClass);
    }

}